package com.souku.finance.application.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.souku.finance.application.R;

/**
 * Created by Administrator on 2017/5/20 0020.
 */
public class CalculationAdapter extends BaseAdapter {

    private Context mContext;
    private String[] numbers = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "0", "0"};

    public CalculationAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return numbers.length;
    }

    @Override
    public Object getItem(int i) {
        return numbers[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        CalculationViewHelp viewHolder = null;

        if (view == null || !(view.getTag() instanceof CalculationViewHelp)) {

            view = LayoutInflater.from(mContext).inflate(R.layout.item_calculation, null);

            viewHolder = new CalculationViewHelp(view);

            view.setTag(viewHolder);

        } else {

            viewHolder = (CalculationViewHelp) view.getTag();

        }

        viewHolder.tvNumber.setText(numbers[i]);

        return view;
    }

    static class CalculationViewHelp {

        TextView tvNumber;

        CalculationViewHelp(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            tvNumber = (TextView) rootView.findViewById(R.id.tv_number);
        }
    }

}
